package com.twetec.cms.adapter.html.frondend.controller;

import com.twetec.cms.adapter.html.frondend.response.R;
import com.twetec.cms.common.constant.RedisConst;
import com.twetec.cms.common.util.cache.RedisCache;
import com.twetec.cms.common.util.validate.ValidateUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @author zhkx
 * @date 2022/2/21 11:01
 */
@Api(tags = "统计")
@RestController
@RequestMapping("/statistics")
public class StatisticsController {

    @Autowired
    private RedisCache redisCache;

    @ApiOperation(value = "测试", notes = "测试")
    @GetMapping("/hello")
    public R hello(@ApiParam(value = "站点id(如果查询站点下的文章，则栏目id传0)", required = true, example = "123456789") @RequestParam(required = false) Long siteId) {
        if (siteId == null || !ValidateUtil.Number(siteId) || siteId <= 0) return R.failureRequestParam().msg("站点id不能为空");

        HashMap<String, Long> map = new HashMap<>();
        map.put("siteId", siteId);
        Integer count;

        Date date = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("ddMMyyyy");
        System.out.println(formatter.format(date));


        redisCache.getObj(RedisConst.REDISKEY_SITE_ACCESS_STATISTICS + formatter.format(date), Map.class);




        return R.success().data("hello world");
    }
}
